package com.atguigu.job;

import com.atguigu.constant.RedisConstant;
import com.atguigu.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class QiniuJob {
    @Autowired
    JedisPool jedisPool;
    public void clearImage(){
        Jedis jedis = jedisPool.getResource();
        Set<String> sdiffSet = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (sdiffSet !=null && sdiffSet.size() >0) {
            for (String filename : sdiffSet) {
                //1.七牛云删除对应的名字（图片）
                QiniuUtils.deleteFileFromQiniu(filename);
                //2.删除redis 中的图片(对应七牛云中的图片)
                jedis.srem(RedisConstant.SETMEAL_PIC_RESOURCES, filename);
                System.out.println("删除成功！");
            }
        }

    }
}
